<?php

namespace App\Http\Controllers;

use App\service\ReturnService;
use App\service\ReviewImages;
use Illuminate\Http\Request;

class Order extends Controller
{
    /**
     * 订单所有分类
     */
    public function orderType(Request $request)
    {
        $user_id = $request->get('user_id');
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')->where('gr_order.user_id',$user_id)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }
    /**
     * 未付款订单
     */
    public function orderNoPay(Request $request){
        $user_id = $request->get('user_id');
        $orderData=-2;
        $pay=0;
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')->where('gr_order.user_id',$user_id)
            ->where('gr_order.order_status',$orderData)->where('gr_order.is_pay',$pay)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }
    /**
     * 待发货
     */
    public function noSendGoods(Request $request){
        $user_id = $request->get('user_id');
        $orderData=0;
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')->where('gr_order.user_id',$user_id)
            ->where('gr_order.order_status',$orderData)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }
    /**
     * 待收货
     */
    public function noReceiveGoods(Request $request){
        $user_id = $request->get('user_id');
        $orderData=1;
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')->where('gr_order.user_id',$user_id)
            ->where('gr_order.order_status',$orderData)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }
    /**
     * 待评价 订单状态显示已签收 才可以评价
     */
    public function noAppraise(Request $request){
        $user_id = $request->get('user_id');
        $orderData=2;
        $is_appraise=0;
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')->where('gr_order.user_id',$user_id)
            ->where('gr_order.order_status',$orderData)->where('gr_order.is_appraise',$is_appraise)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }
    /**
     * 售后
     */
    public function afterSale(Request $request){
        $user_id = $request->get('user_id');
        $data = \App\Models\Order::join('gr_order_goods', 'gr_order.id', '=', 'gr_order_goods.order_id')
            ->join('gr_goods', 'gr_order_goods.goods_id', '=', 'gr_goods.goods_id')
            ->join('gr_aftermarket','gr_aftermarket.order_id','=','gr_order.id')
            ->where('gr_order.user_id',$user_id)
            ->select('gr_order.*', 'gr_order_goods.*', 'gr_goods.goods_name', 'gr_goods.goods_img', 'gr_goods.goods_now_price')->get();
        if (empty($data)) {
            return ReturnService::failedReturn('400', '失败');
        } else {
            return ReturnService::successReturn('200', '成功', $data);
        }
    }

}
